﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.PackageManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.PackageManagement.PackageSchemeVMs
{
    public partial class PackageSchemeListVM : BasePagedListVM<PackageScheme_View, PackageSchemeSearcher>
    {
        
        protected override IEnumerable<IGridColumn<PackageScheme_View>> InitGridHeader()
        {
            return new List<GridColumn<PackageScheme_View>>{
                
                this.MakeGridHeader(x => x.PackageScheme_Name).SetTitle(@Localizer["Page.名称"].Value),
                this.MakeGridHeader(x => x.PackageScheme_Code).SetTitle(@Localizer["Page.编码"].Value),
                this.MakeGridHeader(x => x.PackageScheme_ProductId).SetTitle(@Localizer["Page.装箱产品"].Value),
                this.MakeGridHeader(x => x.PackageScheme_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.PackageScheme_Rules).SetTitle(@Localizer["Page.条码校验规则"].Value),
                this.MakeGridHeader(x => x.PackageScheme_Qty).SetTitle(@Localizer["Page.装箱数量"].Value),
                this.MakeGridHeader(x => x.PackageScheme_EnablePrint).SetTitle(@Localizer["Page.启用打标"].Value),
                this.MakeGridHeader(x => x.PackageScheme_SerialNumber).SetTitle(@Localizer["Page.流水号"].Value),
                this.MakeGridHeader(x => x.PackageScheme_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.PackageScheme_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.PackageScheme_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.PackageScheme_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<PackageScheme_View> GetSearchQuery()
        {
            var query = DC.Set<PackageScheme>()
                
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckContain(Searcher.Rules, x=>x.Rules)
                .CheckEqual(Searcher.Qty, x=>x.Qty)
                .CheckEqual(Searcher.EnablePrint, x=>x.EnablePrint)
                .CheckEqual(Searcher.SerialNumber, x=>x.SerialNumber)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new PackageScheme_View
                {
				    ID = x.ID,
                    
                    PackageScheme_Name = x.Name,
                    PackageScheme_Code = x.Code,
                    PackageScheme_ProductId = x.ProductId,
                    PackageScheme_ProductName = x.ProductName,
                    PackageScheme_Rules = x.Rules,
                    PackageScheme_Qty = x.Qty,
                    PackageScheme_EnablePrint = x.EnablePrint,
                    PackageScheme_SerialNumber = x.SerialNumber,
                    PackageScheme_CreateTime = x.CreateTime,
                    PackageScheme_UpdateTime = x.UpdateTime,
                    PackageScheme_CreateBy = x.CreateBy,
                    PackageScheme_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class PackageScheme_View: PackageScheme
    {
        
        public string PackageScheme_Name { get; set; }
        public string PackageScheme_Code { get; set; }
        public long? PackageScheme_ProductId { get; set; }
        public string PackageScheme_ProductName { get; set; }
        public string PackageScheme_Rules { get; set; }
        public decimal? PackageScheme_Qty { get; set; }
        public bool? PackageScheme_EnablePrint { get; set; }
        public long? PackageScheme_SerialNumber { get; set; }
        public DateTime? PackageScheme_CreateTime { get; set; }
        public DateTime? PackageScheme_UpdateTime { get; set; }
        public string PackageScheme_CreateBy { get; set; }
        public string PackageScheme_UpdateBy { get; set; }

    }

}